import {mapMutations} from 'vuex'

export default {
    ...mapMutations([
        'upToken',
		'upUserInfo'
    ]),
	//用户协议
	
	toRechargeAgreement (){
		let that = this
		if (that.atLoading) {
			//禁止多次点击
			return false
		}
		that.atLoading = true
		uni.navigateTo({
			url: '/pages/my/userAgreement'
		})
		setTimeout(()=>{ //延时指定时间后，再解冻
			that.atLoading = false;
		}, 1000);
	},

	
	toLogin() {
		let that = this;
		uni.getUserInfo({
			success: (res1) => {
				uni.login({
					success: (res) => {
						if (res.code) {
							that.$httpRequest.request({
								url: 'publics/login',
								params: {
									code: res.code,
									userInfo: res1.userInfo,
								},
								success: res => {
									// that.loading = false
									if (res.code === that.$httpConfig.SUCCESS_CODE) {
										that.upToken(res.data.token);
										that.upUserInfo(res.data.userInfo);
										uni.navigateBack({
										    delta: 1
										});
									} else {
										that.$toast.alert({
											content: res.msg,
											callback: result => {
							
											}
										})
									}
								}
							})
						}
					}
				})
			},
			fail: () => {
				console.log("未授权");
				that.upUserInfo({});
			}
		})
	},
    submitForm() {
        let that = this
        if (that.loading) {
            that.$toast.msg('请求中...', {
                icon: 1
            })
            return false
        }
        that.loading = true
			that.$httpRequest.request({
			    that: that,
			    url: 'Publics/login',
			    params: {
			        mobile: that.formData.mobile,
			        code: that.formData.code
			    },
			    success: res => {
			        that.loading = false
			        if (res.code === that.$httpConfig.SUCCESS_CODE) {
			            that.upToken(res.data.token)
                        let url = ''
                        url = '/pages/index/index'
			            uni.switchTab({
			                url
			            })
			        } else {
			            that.$toast.alert({
			                content: res.msg,
			                callback: result => {

			                }
			            })
			        }
			    }
			})

    },
	toReturn(){
		uni.navigateBack({
			delta: 1 // 返回上一级页面。
		})
	}
}
